<?php

function sqlite_escape_string( $string ){
    return SQLite3::escapeString($string);
}

$db = new MyDB();

if(!$db) { 
		echo $db->lastErrorMsg();
}

$sql = "select login,password,uid,admin,name from users where login = '".sqlite_escape_string(@$_POST['login'])."' and password = '".md5(@$_POST['password'])."';";

if(isset($_POST['login'])) {
	$results = $db->query($sql);
	while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
		$uid = $row['uid'];
		$admin = $row['admin'];
		$name = $row['name'];
	}
	if(!empty($uid)) {
		$_SESSION['name'] = $name;
		$_SESSION['admin'] = $admin;
		$_SESSION['uid'] = $uid;
		$_SESSION['logged'] = true;
	} else {
		$_SESSION['logged'] = false;
	}
}

?>